<?php namespace Admin\Model;
use Hdphp\Model\Model;

class Goodslist extends Model{
	//指定表名,固定写法
    protected $table = "goodslist";
	
	
	public function store(){
//		指定同一个goods_gid里的货品不重复
		$list = $this->where("goods_gid=".Q('post.goods_gid',0,'intval'))->get();
		if(!$this->create()) return false;
		$g = 1;
		foreach ($list as $value) {
			if($value['glattrid'] === implode(",",Q('post.glattrid',array()))){$g = 0;} 
		}
	    if(!$g){View::error('货品已存在，如果要修改库存，请点击编辑');return false;}
			if(Q('post.glnum')){
				$glnum = Q('post.glnum');
			}else{
				$glnum = 'G'.mt_rand(0,9).time();
			}
			$new = array(
				'glattrid' => implode(",",Q('post.glattrid',array())),
				'goods_gid' => Q('post.goods_gid',0,'intval'),
				'glnum' => $glnum,
				'glinv' => Q('post.glinv',0,'intval'),
			); 
			$this->add($new);

		return true;
	}
}







